<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="devName" placeholder="" class="layui-input">
                </div>
                <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="signDev-query">
                    <i class="layui-icon layui-icon-search"></i>
                   	 查询
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
					重置
                </button>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="signDev-table" lay-filter="signDev-table"></table>
    </div>
</div>
</body>

<script type="text/html" id="signDev-bar">
    <button sa:hasPermission="admin:signDev:edit" class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" title="修改"><i class="layui-icon layui-icon-edit"></i>
    </button>

   <!-- <button sa:hasPermission="admin:signDev:remove" class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove" title="删除"><i class="layui-icon layui-icon-delete"></i>
    </button>-->
</script>

<script type="text/html" id="signDev-enable">
    <input type="checkbox" id="signDevEnable" name="enable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="signDev-enable" {{ d.devStatus== 0 ? 'checked' : '' }}>
</script>


																																																					

<script type="text/javascript" th:inline="javascript">
	
	window.selectDictLabel=function(datas, value) {
		var actions = [];
	    $.each(datas, function(index, dict) {
	        if (dict.dictValue == ('' + value)) {
	        	var listClass = ("default"== dict.listClass) ? "" : "badge badge-" + dict.listClass;
	        	actions.push(sprintf("<span class='%s'>%s</span>", listClass, dict.dictLabel));
	            return false;
	        }
	    });
	    return actions.join('');
	}
	window.sprintf=function (str) {
	    var args = arguments, flag = true, i = 1;
	    str = str.replace(/%s/g, function () {
	        var arg = args[i++];
	        if (typeof arg === 'undefined') {
	            flag = false;
	            return '';
	        }
	        return arg;
	    });
	    return flag ? str : '';
	}
</script>	
	


<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
				
        let MODULE_PATH = rootPath+"/auth/SignDevController/";
        let cols = [
            [
               {type: 'checkbox',width: '2%'},
	                	
               {title: '主键', field: 'id', align: 'center',width: '1%',hide:true},
    	                	
               {title: '签名设备型号', field: 'devName', align: 'center',width: '8%'},
    	                	
               {title: 'IP地址', field: 'ip', align: 'center',width: '8%'},
    	                	
               {title: '端口', field: 'port', align: 'center',width: '5%'},
    	                	
               {title: '设备证书号', field: 'signNo', align: 'center',width: '8%'},
    	                	
               {title: '数据类型', field: 'dataType', align: 'center',width: '4%'},
    	                	
               {title: '启用状态', field: 'devStatus', align: 'center',toolbar: '#signDev-enable',width: '8%'},
    	                	
               {title: '最大连接数', field: 'connectCount', align: 'center',width: '8%'},
    	                	
               {title: '超时时间', field: 'timeOut', align: 'center',width: '8%'},
               
               {title: '配置文件路径', field: 'confilePath', align: 'left',width: '20%'},
               
               {title: '日志文件路径', field: 'logPath', align: 'left',width: '15%'},
    	                	
               {title: '操作', toolbar: '#signDev-bar', align: 'center',width: '4%'}
            ]
        ]

        //table表单列表
        table.render({
            elem: '#signDev-table',
            url: MODULE_PATH + 'page',
			parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
		        return {
		          "code" : 0,  //使分页参数和回调数据对应
                  "msg" : res.msg,
		          "count": res.totalCount, //解析数据长度
		          "data": res.data //解析数据列表
		        }
		     },
            page: true,
            method: 'get',
            cols: cols,
            skin: 'line',
            toolbar: '#signDev-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        //table图标事件绑定
        table.on('tool(signDev-table)', function (obj) {
            if (obj.event === 'remove') {
                //window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            }
        });

        //查询按钮绑定
        form.on('submit(signDev-query)', function (data) {
            table.reload('signDev-table', {page: {curr: 1}, where: data.field})
            return false;
        });

        //修改
        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改',
                shade: 0.1,
                area: ['500px', '500px'],
                content: MODULE_PATH + 'edit/' + obj.data['id']
            });
        }
        //状态切换绑定
        form.on('switch(signDev-enable)', function (obj) {
	        let curChecked = obj.elem.checked;
			let operate;
			let tip;
            if (curChecked) {
                operate = '0';
                tip = "启用";
            } else {
                operate = '1';
                tip = "禁用";
            }
			layer.confirm('确定要'+tip+'该设备', {icon: 3, title: '提示'}, function (index) {
	            let loading = layer.load()
	            $.ajax({
	                url: MODULE_PATH+'/updateEnable',
	                data: JSON.stringify({id: obj.elem.value,devStatus:operate}),
	                dataType: 'json',
	                contentType: 'application/json',
	                type: 'put',
	                success: function (result) {
	                    layer.close(loading);
	                    if (result.successful) {
							window.refresh();
	                        layer.msg(result.msg, {icon: 1, time: 2000}, function () {
								
	                        });
	                    } else {
							obj.elem.checked=!curChecked;
		        			layui.form.render(); // 重新渲染。。。
	                        layer.msg(result.msg, {icon: 2, time: 5000});
	                    }
	                }
	            })
            }, function(){
				obj.elem.checked=!curChecked;
		        layui.form.render(); // 重新渲染。。。
			});
        });
        
        //刷新按钮
        window.refresh = function () {
            table.reload('signDev-table');
        }
    })
</script>
</html>